package com.wms.controller;

import com.wms.bean.ResultBean;
import com.wms.core.R;
import com.wms.entity.Set;
import com.wms.exception.V;
import com.wms.service.SetService;
import com.wms.utils.Assert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
@Api(tags = "skh-自动触发设置")
public class SetController {

    @Autowired
    SetService setService;

    @ApiOperation("保存自动触发")
    @PostMapping("/set")
    public ResultBean save(@Validated  @RequestBody Set set, BindingResult result) {
        V.validate(result);
        Assert.isEmpty(set.getCategoryCodes(), "请选择物料类别");
        //不为空
        int rs = setService.saveOrUpdate(set);
        return R.saveResult(rs);
    }

    @GetMapping("/set/queryId")
    @ApiOperation("根据类型查询对应的id")
    public ResultBean queryByType(@RequestParam int type) {
        Set set = setService.queryByType(type);
        if (set!=null){
            return  R.success("查询成功",set);
        }
        return R.fail("查询失败");
    }
}
